<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="保险合同" prop="toubaoId">
        <el-select v-model="queryParams.insureId" placeholder="请选择保险合同" clearable style="width: 200px"
                   filterable>
          <el-option
              v-for="dict in insureList"
              :key="dict.insureId"
              :label="dict.contractName"
              :value="dict.insureId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="日期" prop="startDate" label-width="60px">
        <el-date-picker
            v-model="times"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['risk:contract:statics']"
        >导出
        </el-button>
      </el-form-item>
    </el-form>

    <el-row style="text-align: center;display: flex;">
      <div style="margin-left: auto;width: 360px">
        <el-col :span="6" style="margin-left: auto;margin-top: 10px">
          全部汇总：
        </el-col>
        <el-col :span="9">
          <div>
            <el-statistic
                :value-style="{color:'red'}"
                group-separator=","
                :precision="2"
                :value="staticForm.planAmount"
            >
              <template slot="title">
                <div style="font-size: 16px;color: #1C1C1C">计划总回款</div>
              </template>
              <template slot="suffix">
                <div style="color: red">元</div>
              </template>
            </el-statistic>
          </div>
        </el-col>
        <el-col :span="9">
          <div>
            <el-statistic
                :value-style="{color:'red'}"
                group-separator=","
                :precision="2"
                :value="staticForm.realAmount"
            >
              <template slot="title">
                <div style="font-size: 16px;color: #1C1C1C">实际总回款</div>
              </template>
              <template slot="suffix">
                <div style="color: red">元</div>
              </template>
            </el-statistic>
          </div>
        </el-col>
      </div>

    </el-row>
    <el-table v-loading="loading" :data="contractList">
      <el-table-column label="合同名称" align="center" prop="contractName" :min-width="150"/>
      <el-table-column label="保单号码" align="center" prop="insureNo" :min-width="150"/>
      <el-table-column label="风控及技术服务金额(元)" align="center" prop="riskAmount" :min-width="160"/>
      <el-table-column label="批次名称" align="center" prop="planName" width="120"/>
      <el-table-column label="计划回款金额(元)" align="center" prop="planAmount" width="120"/>
      <el-table-column label="计划回款时间" align="center" prop="planDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.planDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付比例(%)" align="center" prop="rate" width="100"/>
      <el-table-column label="支付责任人" align="center" prop="responsiblePerson" width="100"/>
      <el-table-column label="实际支付金额(元)" align="center" prop="realAmount" width="120"/>
      <el-table-column label="实际支付时间" align="center" prop="realDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.realDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付比例(%)" align="center" prop="realRate" width="100"/>
      <el-table-column label="支付责任人" align="center" prop="responsiblePersonReal" width="120"/>
      <el-table-column label="计划金额(元)" align="center" prop="riskAmountPlan" width="120"/>
      <el-table-column label="已收(元)" align="center" prop="riskAmountReal"/>
      <el-table-column label="未收(元)" align="center" prop="riskAmountNot"/>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="handleQuery"
    />
  </div>
</template>
<script>

import {getRiskStatics, getXlMainList, staticsRiskAmount} from "@/api/risk/contract";
import {isEmpty} from "@/utils/validate";

export default {
  name: "RiskCost",
  data() {
    return {
      staticForm: {},
      total: 0,
      contractList: [],
      loading: false,
      times: [],
      showSearch: true,
      insureList: [],
      queryParams: {
        pageSize: 10,
        pageNo: 1,
        insureId: undefined,
        startDate: undefined,
        endDate: undefined
      }
    }
  },
  mounted() {
    this.getXlMainListSelect()
    this.handleQuery()
  },
  methods: {
    getXlMainListSelect() {
      getXlMainList().then(res => {
        this.insureList = res.data
      })
    },
    handleExport() {
      this.download('/risk/contract/exportStatics', {
        ...this.queryParams
      }, `风控费用_${new Date().getTime()}.xlsx`)
    },
    handleQuery() {
      this.queryParams.startDate = null
      this.queryParams.endDate = null
      if (!isEmpty(this.times)) {
        this.queryParams.startDate = this.times[0]
        this.queryParams.endDate = this.times[1]
      }
      getRiskStatics(this.queryParams).then(res => {
        this.contractList = res.rows
        this.total = res.total
      })
      staticsRiskAmount(this.queryParams).then(res => {
        if (isEmpty(res.data)) {
          this.staticForm.planAmount = 0
          this.staticForm.realAmount = 0
          return
        }
        this.staticForm = res.data
      })
    },
    resetQuery() {
      this.times = []
      this.queryParams = {
        pageSize: 10,
        pageNo: 1,
        insureId: undefined,
        startDate: undefined,
        endDate: undefined
      }
      this.handleQuery()
    }
  }
}
</script>
<style scoped lang="scss">

</style>
